import { mergeOptions } from '../utils/index'

export function initGlobalApi(Vue) {
    // 这里进行了options初始化
    Vue.options = {}
    Vue.Mixin = function (mixin) {
        this.options = mergeOptions(this.options, mixin)
        // console.log(Vue.options);
    }
    Vue.options.components = {}
    Vue.component = function (id, componentRef) {
        // 这里进行组件的注册
        componentRef.name = componentRef.name || id
        componentRef = this.extend(componentRef)
        this.options.components[id] = componentRef
    }

    Vue.extend = function (options) {
        // const super = this
        const Sub = function VueComponent(options) {
            this._init(options)
        }
        Sub.prototype = Object.create(this.prototype)
        Sub.prototype.constructor = Sub
        Sub.options = mergeOptions(this.options, options)
        return Sub
    } 

}